package edu.uni.userBaseInfo1.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import edu.uni.example.config.ExampleConfig;
import edu.uni.userBaseInfo1.bean.Student;
import edu.uni.userBaseInfo1.bean.StudentExample;
import edu.uni.userBaseInfo1.bean.User;
import edu.uni.userBaseInfo1.bean.UserExample;
import edu.uni.userBaseInfo1.mapper.StudentMapper;
import edu.uni.userBaseInfo1.mapper.UserMapper;
import edu.uni.userBaseInfo1.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author laizhouhao
 * @Description Student实体类的service层接口的实现类
 * @Date 10:11 2019/4/30
 **/
//Service类的注解，标志这是一个服务层接口类，这样才能被Spring”“”“”“”"扫描"到
@SuppressWarnings("ALL")
@Service
public class StudentServiceImpl implements StudentService {
    //持久层接口的对象
    @Autowired
    private StudentMapper studentMapper;  //爆红时由于编译器问题，不影响运行
    @Autowired
    private UserMapper userMapper;

    //配置类，规定了上传文件的路径和分页查询每一页的记录数
    @Autowired
    private ExampleConfig config;

    /**
     * Author: laizhouhao 10:15 2019/4/30
     * @param id
     * @return Student
     * @apiNote: 通过id查询一个学生记录
     */
    public Student selectById(long id) {
        return studentMapper.selectByPrimaryKey(id);
    }

    /**
     * Author: laizhouhao 18:34 2019/5/6
     * @param user_id
     * @return List<Student>
     * @apiNote: 根据用户id查找学生信息
     */
    @Override
    public List<Student> selectByUserId(Long user_id) {
        StudentExample studentExample = new StudentExample();
        studentExample.createCriteria().andUserIdEqualTo(user_id)
                .andDeletedEqualTo(false);
        return studentMapper.selectByExample(studentExample);
    }

    @Override
    public Student selectByStuNo(String studentNo) {
        StudentExample studentExample = new StudentExample();
        studentExample.createCriteria().andStuNoEqualTo(studentNo);
        List<Student> studentList = studentMapper.selectByExample(studentExample);
        if(studentList!=null && studentList.size()>0){
            return studentList.get(0);
        }
        return null;
    }

}
